import ctypes
import sys

def my_function():
    x = 10
    print(f"Before modification: x = {x}")
    frame = sys._getframe(0) # Get the current frame
    frame.f_locals['x'] = 20 # Modify f_locals
    print(f"After f_locals modification (before sync): x = {x}") # x is still 10
    ctypes.pythonapi.PyFrame_LocalsToFast(ctypes.py_object(frame), ctypes.c_int(0))
    print(f"After sync: x = {x}") # x is now 20
my_function()